import { defineStore } from 'pinia'
import type { HospitalDetailData, HospitalDetail, DeparmentResponseData, DeparmentArr } from '@/api/hospital/type'
import { reqHospitalDetail, reqHospitalDeparment } from '@/api/hospital/index'
import { ref } from 'vue'

// 选取组合式api构建分支仓库

export const useDetailStore = defineStore('detail', () => {
    //actions 获取医院详情数据
    const getHospitalDetail = async (hoscode: string) => {
        const res: HospitalDetailData = await reqHospitalDetail(hoscode)
        if (res.code === 200) {
            hospitalDetail.value = res.data
        }
    }
    //actions 获取医院科室数据
    const getDepartment = async (hoscode: string) => {
        const res: DeparmentResponseData = await reqHospitalDeparment(hoscode)
        if (res.code === 200) {
            hospitalDepartment.value = res.data
        }
    }

    // states 医院详情数据
    const hospitalDetail = ref<HospitalDetail>()
    // states 医院科室数据
    const hospitalDepartment = ref<DeparmentArr>()

    return { hospitalDetail, hospitalDepartment, getHospitalDetail, getDepartment }
})